<?php
// Test of the limits of the Cubie construct
class UTCube extends UnitTestCase {
    function testConstruct() {
        try {
            $myCube = new cube();
            $this->pass('Cube constructor test');
        }
        catch (Exception $e) {$this->fail('Cube constructor test');}
    }

    function testToString() {
        $myCube = new cube();
        $mystring = $myCube->__toString();
        $this->assertEqual($mystring, '(1 2 3 4 5 6 7 8 9 10 11 12) (1 2 3 4 5 6 7 8)');
    }

    function testTurn() {
        $myCube = new cube();
        $myCube->turn('U');
        $mystring = $myCube->__toString();
        $this->assertEqual($mystring, '(2 3 4 1 5 6 7 8 9 10 11 12) (2 3 4 1 5 6 7 8)');

        $myCube = new cube();
        $myCube->turn('R');
        $mystring = $myCube->__toString();
        $this->assertEqual($mystring, '(1 6- 3 4 5 10- 2- 8 9 7- 11 12) (1 6- 2+ 4 5 7+ 3- 8)');

        $myCube = new cube();
        $myCube->turn('B');
        $mystring = $myCube->__toString();
        $this->assertEqual($mystring, '(1 2 7 4 5 6 11 3 9 10 8 12) (1 2 7- 3+ 5 6 8+ 4-)');

        $myCube = new cube();
        $myCube->turn('L');
        $mystring = $myCube->__toString();
        $this->assertEqual($mystring, '(1 2 3 8- 4- 6 7 12- 9 10 11 5-) (4+ 2 3 8- 1- 6 7 5+)');

        $myCube = new cube();
        $myCube->turn('F');
        $mystring = $myCube->__toString();
        $this->assertEqual($mystring, '(5 2 3 4 9 1 7 8 6 10 11 12) (5- 1+ 3 4 6+ 2- 7 8)');

        $myCube = new cube();
        $myCube->turn('D');
        $mystring = $myCube->__toString();
        $this->assertEqual($mystring, '(1 2 3 4 5 6 7 8 12 9 10 11) (1 2 3 4 8 5 6 7)');

        $myCube = new cube();
        $myCube->turn('M');
        $mystring = $myCube->__toString();
        $this->assertEqual($mystring, '(3- 2 11- 4 5 6 7 8 1- 10 9- 12) (1 2 3 4 5 6 7 8)');

        $myCube = new cube();
        $myCube->turn('E');
        $mystring = $myCube->__toString();
        $this->assertEqual($mystring, '(1 2 3 4 8- 5- 6- 7- 9 10 11 12) (1 2 3 4 5 6 7 8)');

        $myCube = new cube();
        $myCube->turn('S');
        $mystring = $myCube->__toString();
        $this->assertEqual($mystring, '(1 4- 3 12- 5 6 7 8 9 2- 11 10-) (1 2 3 4 5 6 7 8)');

        try {
            $myCube->turn('dummy');
            $this->fail('Bad dummy turn');
        }
        catch (Exception $e) {
            $this->pass('Dummy turn OK');
        }
        // R2 U R U R' U' R' U' R' U R'
        $myCube = new cube();
        $myCube->turn('R');
        $myCube->turn('R'); // R2
        $myCube->turn('U');
        $myCube->turn('R');
        $myCube->turn('U');
        $myCube->turn('R');
        $myCube->turn('R');
        $myCube->turn('R'); // R'
        $myCube->turn('U');
        $myCube->turn('U');
        $myCube->turn('U'); // U'
        $myCube->turn('R');
        $myCube->turn('R');
        $myCube->turn('R'); // R'
        $myCube->turn('U');
        $myCube->turn('U');
        $myCube->turn('U'); // U'
        $myCube->turn('R');
        $myCube->turn('R');
        $myCube->turn('R'); // R'
        $myCube->turn('U'); // U
        $myCube->turn('R');
        $myCube->turn('R');
        $myCube->turn('R'); // R'
        $mystring = $myCube->__toString();
        $this->assertEqual($mystring, '(2 4 3 1 5 6 7 8 9 10 11 12) (1 2 3 4 5 6 7 8)');
    }

    private function testMultipleTurn()
    {
        $myCube = new Cube();
        $myCube->alg("R R U R U R R R U U U R R R U U U R R R U R R R");
        $mystring = $myCube->__toString();
        $this->assertEqual($mystring, '(2 4 3 1 5 6 7 8 9 10 11 12) (1 2 3 4 5 6 7 8)');
    }
}
?>
